package com.wenwei.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.amap.api.services.help.Tip;
import com.wenwei.parking.R;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by nidalee on 2017/9/23.
 */

public class SearchAddressAdapter extends RecyclerView.Adapter<SearchAddressAdapter.MyViewHolder> {

    public interface CallBack {
        void onItemClick(Tip t);
    }

    private List<Tip> mList;

    public void setmList(List<Tip> list) {
        this.mList = list;
    }

    private CallBack mCallBack;

    public void setmCallBack(CallBack callBack) {
        this.mCallBack = callBack;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_search_address, parent, false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mCallBack.onItemClick(mList.get(position));
            }
        });
        holder.name.setText(mList.get(position).getName());
        holder.address.setText(mList.get(position).getAddress());
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.name)
        TextView name;
        @Bind(R.id.address)
        TextView address;
        public MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }


}
